package cn.jinshengda.utils;

import java.text.SimpleDateFormat;
import java.util.*;

public class YearUtils {

    public static List<String> month= Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12");


    public static List<String> getMonth(){
        Calendar cal = Calendar.getInstance();
        List<String> list=new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for (String s : month) {
            if(list.size()==0){
                list.add(year+"-"+s+"-"+"01");
            }else if(list.size()==11){
                list.add(year+"-"+s+"-"+"30");
            }else {
                list.add(year+"-"+s);
            }
        }
        return list;
    }

    public static List<String> getYear(String startMonth,String endMonth){
        List<String> nowYearMonth=new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar cal = Calendar.getInstance();
        try{
            cal.setTime(sdf.parse(startMonth));
            for (long d = cal.getTimeInMillis(); d <= sdf.parse(endMonth).getTime(); d = get_D_Plaus_1(cal)) {
                nowYearMonth.add(sdf.format(d));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return nowYearMonth;
    }


    public static long get_D_Plaus_1(Calendar c) {
        c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
        return c.getTimeInMillis();
    }

}
